package logic;

import logic.SimulationRunState;


/**
 * Trieda pre stav jedneho simulacneho behu. 
 */
public class SimulationRunState {
    public static final int STATE_WAITING_FOR_START = 0;
    public static final int STATE_INIT              = 1;  //inicializacia
    public static final int STATE_RUNNING           = 2;  //simulacia bezi
    public static final int STATE_FINISHING         = 3;  //simulacia sa ukoncuje sama -> statistiky
    public static final int STATE_FINISHED          = 4;  //simulacia sa uspesne skoncila
    public static final int STATE_STOPPING          = 5;  //simulacia sa zacina nasilne ukoncovat
    public static final int STATE_STOPPED           = 6;  //simulacia sa nasilne skoncila
    public static final int STATE_ERROR             = 7;  //chybovy stav
    
    private static final String[] descpritons = {
        "Waiting for start",
        "Initializing",
        "Simulating",
        "Finishing - evaluating statistics",
        "Finished",
        "Stopping",
        "Stopped",
        "Error"
    };
    
    /**
     * identifikator stavu, na zaklade ktoreho sa vytvara popis stavu
     */
    private int state;

    /**
     * pocet vsetkych uloh v simulacii
     */
    private int tasksCount;

    /**
     * pocet ukoncenych uloh v simulacii
     */
    private int doneTasksCount;
    
    /**
     * Vytvori kopiu daneho stavu.
     */
    public SimulationRunState(SimulationRunState original) {
        this();
        state = original.state;
        tasksCount = original.tasksCount;
        doneTasksCount = original.doneTasksCount;
    }

    public SimulationRunState() {
        super();
        state = STATE_WAITING_FOR_START;
        tasksCount = 0;
        doneTasksCount = 0;
    }

    /**
     * Vracia true, ak simulacia bezi - urcuje sa to zo stavu
     */
    public boolean isRunning() {
        return ((state == STATE_INIT) ||
                (state == STATE_RUNNING) ||
                (state == STATE_STOPPING));
    }

    /**
     * Popis stavu - napr. Inicializacia entit, Simulacia, ...
     */
    public String getStateDescription() {
        return new String(descpritons[state]);
    }

    void setState(int newState) {
        state = newState;
    }

    public int getState() {
        return state;
    }

    public int getTasksCount() {
        return tasksCount;
    }

    public void setTasksCount(int val) {
        this.tasksCount = val;
    }

    public int getDoneTasksCount() {
        return doneTasksCount;
    }

    public void incDoneTasksCount() {
        doneTasksCount++;
    }
    
}
